package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionManager {
  
	String userName = "root";
    String password = "";
    String url = "jdbc:mysql://localhost/software";
   
	private static ConnectionManager connectionInstance = null;
  
  public ConnectionManager(){
	  
  }
  
  public static synchronized ConnectionManager getInstance() {
	if(connectionInstance == null) {
	  connectionInstance = new ConnectionManager(); 		
	}
	return connectionInstance;
  }
  
  public Connection getConnection(){
	  
	  Connection conn = null;
	  try {
		  Class.forName("com.mysql.jdbc.Driver").newInstance ();
		  conn = DriverManager.getConnection (url, userName, password);
		  
		  System.out.println("Connection Established");
	  }  catch (ClassNotFoundException e) {
		  e.printStackTrace();
	  }	 catch (SQLException e) {
		  e.printStackTrace();
	  } catch (InstantiationException e) {
		  e.printStackTrace();
	  } catch (IllegalAccessException e) {
		  e.printStackTrace();
	  }
	  return conn;
  }

  public void closeConnection(Connection conn){
	try {
	  conn.close();
	} catch (SQLException e) {
		
	}
  } 
  
}
